import api from '@/common/request/index.js'
const imgUrl = 'https://mystore-1304299581.cos.ap-guangzhou.myqcloud.com/static/image/'

const state = {
	user: {
	},
	menu: {
		text: "新品上线好物推荐立即抢好礼",
		info: [{
				id: 0,
				img: imgUrl + "icon_09.png",
				label: "我的卡券",
				url: '/pages/user/coupons/index'
			},
			{
				id: 1,
				img: imgUrl + "icon_13.png",
				label: "我的积分",
				url: '/pages/user/score/index'
			},
			{
				id: 2,
				img: imgUrl + "icon_14.png",
				label: "我的订单",
				url: '/pages/user/order/index'
			},
			{
				id: 3,
				img: imgUrl + "icon_15.png",
				label: "我的拼团",
				url: '/pages/user/myteam/index'
			},
		],
	},
	grid: [
		{
			"id": 0,
			"img": imgUrl + "collect.png",
			"label": "我的收藏",
			"url": "/pages/user/collect/index"
		},
		{
			"id": 1,
			"img": imgUrl + "b.png",
			"label": "个人信息",
			"url": "/pages/user/info/index"
		},
		{
            "id": 3,
            "img": "/static/image/b.png",
            "label": "我的消息",
            "url": "/pages/user/message/index"
        },{
            "id": 4,
            "img": "/static/image/fit.png",
            "label": "我的福利",
            "url": '/pages/welfare/index'
        }
	],
	//我的收藏列表
	collect: [],
	// 积分规则
	pointsRule: [],
	// 卡卷
	coupons: [],
	// 卡卷详情
	couponsDetail: {},
	memberearnPoints: {}, // 签到积分规则
	membersignIn: {}, // 每日签到
    //我的消息列表
    messageList: [],
    // 消息详情
    message_detail: {},
	// 用户协议
	agressment: [],
	Location: {
		longitude: '117.661801',
		latitude: '24.510897'
	}, // 经纬度
	placeType: 0, // 地址选择判断
}
// 同步
const mutations = {
	set_user(state, payload) {
		state.user = payload
	},
	set_collect(state, payload) {
	    state.collect.push(payload)
	},
	set_membercoupon(state, payload) {
	    state.coupons = payload 
	},
	set_couponsDetail(state, payload) {
	    state.couponsDetail = payload 
	},
	set_memberearnPoints(state, payload) {
	    state.memberearnPoints = payload 
	},
	set_message_detail(state, payload) {
		state.message_detail = payload
	}
}
// 异步
const actions = {
	get_user({commit}, payload) {
		commit('set_user', payload)
	},
	get_collect( {commit}, payload) {
	    commit('set_collect', payload)
	},
	// 设置消息详情
	get_message_detail({commit}, payload) {
		commit('set_message_detail', payload)
	},
	// 查询积分规则
	// 查询签到积分规则
	get_memberearnPoints({commit, state}, payload) {
		 commit('set_memberearnPoints', payload)
	},
	// 每日签到
	get_membersignIn({commit, state}, payload) {
      return new Promise((resolve, reject) => {
          api('membersignIn', payload).then(res => {
              state.membersignIn = res.data;
			  resolve(res.data);
          })
      })
	},
	get_membercoupon({commit, state}, payload) {
		commit('set_membercoupon', payload)
	},
	get_couponsDetail({commit, state}, payload) {
		commit('set_couponsDetail', payload)
	},
	get_pointsRuleS({commit, state}, payload) {
	    state.pointsRule = payload
	},
	get_agressment({commit, state}, payload) {
	    state.agressment = payload
	},
	get_Location({commit, state}, payload) {
	    state.Location = payload
	},
	get_placeType({commit, state}, payload) {
	    state.placeType = payload
	},
}



export default {
	namespaced: true,
	state,
	mutations,
	actions
}
